﻿using System;
using System.Threading;
using System.Windows.Forms;

namespace NetworkFileShare.Test.EndToEnd {

    class ApplicationRunner {

        const int DefaultTimeout = 1000;
        const int DefaultPolling = 100;

        MainClientFormDriver mainClientFormDriver;

        AssertProbe assertProbe;

        public ApplicationRunner() {
            assertProbe = new AssertProbe(DefaultTimeout, DefaultPolling);
        }

        public void ConnectsTo(NetworkPeer peer) {
            CreateMainClientDriver(UsingANewShownMainClientForm());
            mainClientFormDriver.ShowsIdleForm();
        }

        void CreateMainClientDriver(MainClientForm applicationForm) {
            mainClientFormDriver = new MainClientFormDriver(applicationForm, assertProbe);
        }

        MainClientForm UsingANewShownMainClientForm() {
            var applicationForm = new MainClientForm(NetworkPeer.address, NetworkPeer.port);
            applicationForm.Show();
            return applicationForm;
        }

        public void ShowsSuccessfulConnectionStatus() {
            mainClientFormDriver.ShowsConnectedStatus();
        }

    }
}